package kama;

import java.util.ArrayDeque;
import java.util.Queue;
import java.util.Scanner;

public class Test0110 {
}

class Main0110_1{
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int length = scanner.nextInt();
        Queue<String> strings = new ArrayDeque<>(length);
        Queue<String> strings1 = new ArrayDeque<>(length);
        String start = scanner.next();
        String end = scanner.next();
        scanner.nextLine();
        for (int i = 0; i < length; i++) strings.offer(scanner.next());

        Queue<String> deque = new ArrayDeque<>(length);
        Queue<String> deque1 = new ArrayDeque<>(length);
        deque.add(start);
        int count = 1;

        while (!deque.isEmpty()&&!strings.isEmpty()){
            count++;
            while (!deque.isEmpty()){
                String now = deque.poll();
                if (isAbleChange(now,end)){
                    System.out.println(count);
                    return;
                }
                while (!strings.isEmpty()){
                    String poll = strings.poll();
                    if (isAbleChange(now,poll)){
                        deque1.offer(poll);
                    }else {
                        strings1.offer(poll);
                    }
                }
                Queue<String> temp = strings;
                strings = strings1;
                strings1 = temp;
            }
            Queue<String> temp = deque;
            deque=deque1;
            deque1=temp;
        }

        System.out.println(0);
    }

    public static boolean isAbleChange(String a, String b){
        int length = a.length();
        int count = 0;
        for (int i = 0; i < length; i++){
            if (a.charAt(i) != b.charAt(i))
                if (++count>1) return false;
        }
        return true;
    }
}